/*
 * bsp_can.c
 *
 *  Created on: 2023��4��11��
 *      Author: chenwangang
 */

#include "bsp_can_cfg.h"
#include "bsp_can_driver.h"
#include "user_define.h"

can_buff_config_t buff_RxTx_Cfg =
{
    .enableFD = false,
    .enableBRS = false,
    .fdPadding = 0U,
    .idType = CAN_MSG_ID_STD,
    .isRemote = false
};

/* global receive buffer */
can_message_t g_can_recv_msg;
can_message_t g_gate_can_recv_msg;
can_message_t g_htcu_can_recv_msg;
can_message_t g_sensor_can_recv_msg;
can_message_t g_musicloud_can_recv_msg;
/* global send buffer*/
can_message_t g_can_g_send_msg;
/* global EOL receive buffer*/
can_message_t g_can_eol_recv_msg;
/* global EOL send buffer*/
can_message_t g_can_eol_g_send_msg;


/*RX can message config*/
const tRxMsgConfig g_rx_msg_config[] =
{
    {RX_MAILBOX_FUN_ID,   RX_FUN_ADDR_ID,   RX_FUN_ADDR_ID_MASK,   RX_FUN_ADDR_ID_TYPE}, /*UDS Rx function ID*/
    {RX_MAILBOX_PHY_ID,   RX_PHY_ADDR_ID,   RX_PHY_ADDR_ID_MASK,   RX_PHY_ADDR_ID_TYPE},  /*UDS RX physical ID*/
    {RX_MAILBOX_1_NORMAL, RX_MSG_ID_GATE,   RX_MSG_ID_GATE_MASK,   RX_MSG_ID_GATE_TYPE},  /*GATE RX normal ID*/
    {RX_MAILBOX_2_NORMAL, RX_MSG_ID_HTCU,   RX_MSG_ID_HTCU_MASK,   RX_MSG_ID_HTCU_TYPE},    /*HTCU RX normal ID*/
    {RX_MAILBOX_3_NORMAL, RX_MSG_ID_SENSOR, RX_MSG_ID_SENSOR_MASK, RX_MSG_ID_SENSOR_TYPE}, /*SENSOR RX normal ID*/
    {RX_MAILBOX_4_NORMAL, RX_MSG_ID_MUSICLOUD,   RX_MSG_ID_MUSIC_MASK,   RX_MSG_ID_MUSIC_TYPE}    /*MUSIC RX normal ID*/
};

/*rx can message num*/
const uint8_t g_rx_can_msg_id_num = sizeof(g_rx_msg_config) / sizeof(g_rx_msg_config[0u]);


/*TX can message config*/
const tTxMsgConfig g_tx_msg_config[] =
{
    {TX_RESP_ADDR_ID, TX_MAILBOX_UDS,    TX_RESP_ADDR_ID_TYPE, transmit_can_msg_callback}, /*UDS TX can message*/
    {TX_ADDR_ID, TX_MAILBOX_NORMAL, TX_ID_TYPE, NULL}, /*TAIL TX can message*/
    {TX_ID_1, TX_MAILBOX_1, TX_ID_TYPE, NULL},
    {TX_ID_2, TX_MAILBOX_1, TX_ID_TYPE, NULL},
    {TX_ID_3, TX_MAILBOX_1, TX_ID_TYPE, NULL},
    {TX_ID_4, TX_MAILBOX_1, TX_ID_TYPE, NULL},
    {TX_ID_5, TX_MAILBOX_1, TX_ID_TYPE, NULL},
    {TX_ID_6, TX_MAILBOX_1, TX_ID_TYPE, NULL},
    {TX_ID_7, TX_MAILBOX_1, TX_ID_TYPE, NULL},
    {TX_ID_8, TX_MAILBOX_1, TX_ID_TYPE, NULL},
    {TX_ID_9, TX_MAILBOX_1, TX_ID_TYPE, NULL},
};

/*tx can message num*/
const uint8_t g_tx_can_msg_id_num = sizeof(g_tx_msg_config) / sizeof(g_tx_msg_config[0u]);

/*初始化RX数据*/
union protocol_64bit_GATE g_gate_64bits;
union protocol_64bit_HTCU g_htcu_64bits;
union protocol_64bit_SENSOR g_sensor_64bits;
union protocol_64bit_MUSICLOUD g_musicloud_64bits;

/*初始化TX数据*/
union protocol_SendMsg g_send_msg;